package LeetCode.month02.day43;

import java.util.HashSet;
import java.util.Set;

public class No202 {
    public static void main(String[] args) {
        System.out.println(isHappy(2));
    }
    public static boolean isHappy(int n) {
        Set<Integer> set = new HashSet<>();
        set.add(n);
        while(n!=1){
            int sum = 0;
            while(n>0){
                sum+=(int)(Math.pow(n%10,2));
                n/=10;
            }
            if(set.contains(sum)){
                return false;
            }
            set.add(sum);
            n=sum;
        }
        return true;
    }
}
